package pv3d.haxe.july152030 {
        import flash.events.Event;
        
        import org.papervision3d.core.proto.LightObject3D;
        import org.papervision3d.lights.PointLight3D;
        import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
        import org.papervision3d.objects.DisplayObject3D;
        import org.papervision3d.objects.primitives.Cylinder;
        import org.papervision3d.view.BasicView;        

        public class ScaleToDistanceMain extends BasicView {
        	
                private var light : LightObject3D;
                private var origin : DisplayObject3D;
                private var container : DisplayObject3D;

                public function ScaleToDistanceMain() {
                        
                        
                        super(640, 320, false, false, "Debug");
                        setup();        
                        
                }
                
                protected function setup():void{
                        viewport.opaqueBackground = 0xffffff;
                        
                        cameraAsDebugCamera3D.near = 10;
                        cameraAsDebugCamera3D.far = 10000;
                        cameraAsDebugCamera3D.propsDisplay.visible = true;
                        
                        light = new PointLight3D();
                        
                        container = new DisplayObject3D();
                        container.z = 500;
                        scene.addChild(container);
                        
                        origin = new DisplayObject3D();
                        container.addChild(origin);
                        
                        for (var i : Number = 0; i < 150; i++) {
                                var triangle : Cylinder = new Cylinder(new FlatShadeMaterial(light, 0xff1111 * i, 0x000000), 100, 100, 1, 1);
                                triangle.x = Math.cos(i) * 10 * i;
                                triangle.y = Math.sin(i) * 10 * i;
                                
                                var distance:Number = triangle.distanceTo(origin);
                                
                                triangle.scale = distance / 1000;
                                triangle.lookAt(origin);
                                
                                container.addChild(triangle);
                        }
                        
                        addEventListener(Event.ENTER_FRAME, onRender);
                }
                
                private function onRender(event : Event) : void {
                        singleRender();
                }
        }
}
